<template>
	<view class="home">
		<view class="h_header">
			<view class="hh_cicle">
				<image src="/static/images/home/logo.png" class="hc_imgs"></image>
			</view>
			<view class="login_box">
				<text v-if="!loginFlag" class="hc_login l_box_txt1">Hi~ 智初小交欢迎您!</text>
				<view class="l_b_box">
					<text class="hc_login">{{
            loginFlag
              ? String(mobileNo).replace(/(\d{3})\d{4}(\d{4})/, "$1****$2")
              : "未登录，请登录"
          }}</text>
					<text id="LOGIN_BTN" class="l_b_login" v-if="!loginFlag" @click="jumpLogin">登录</text>
				</view>
				<text class="l_login_txt" v-if="loginFlag">欢迎使用智初小交~</text>
			</view>
		</view>
		<view class="h_car">
			<view class="hcc_item" @click="" v-for="(item, ind) in QRList" :key="ind" @click="jumpRepastTo(item)">
				<image class="home_hc_img" :src="item.icon"></image>
				<text class="hc_txt h_h_title" :style="{
            left:
              ind == 0
                ? '15px'
                : ind == 1
                ? '30%'
                : ind == 2
                ? '55%'
                : ind == 3
                ? '80%'
                : ''
          }">{{ item.menuTitle }}</text>
			</view>
		</view>
		<view class="h_notice">
			<view class="h_n_box">
				<image class="n_img" src="/static/images/home/ba.png"></image>
				<view class="txt_box">
					<view v-if="newList.length > 0">
						<swiper style="height: 34rpx;" vertical="true" autoplay="false" duration="500" interval="4000">
							<swiper-item v-for="(item, index) in newList" :key="index">
								<view class="s_txt">{{ item.msgContent }}</view>
							</swiper-item>
						</swiper>
					</view>
					<view v-else>
						<view class="s_txt">暂无公告通知</view>
					</view>
				</view>
			</view>
		</view>
		<!-- <view class="h_notices">
		<swiper style="height: 130rpx;width: 100%" :interval="3000" :duration="1000" autoplay="false"
		 :current="topSwiperIndex" @change="topSwiperTab">
			<swiper-item v-for="(item,index) in topSwiper" :key="index">
				<view class="swiper-item">
					<image :src="item.src" mode="aspectFill"></image>
				</view>
			</swiper-item>
		</swiper>
	</view> -->
		<view class="h_content" :style="{ height: height }">
			<view class="hc_item1">
				<text class="hc_txt1">便捷服务</text>
				<view class="hc_list1">
					<view class="hcc_item1" v-for="(item, index) in homeList" :key="index" @click="jumpRepastTo(item)">
						<image class="hc_img" :src="item.icon"
							:style="item.menuTitle == '人脸采集' ? 'width: 70rpx;height: 70rpx;margin-bottom:0;margin-top: 3px;': ''">
						</image>
						<text class="hc_txt"
							:style="item.menuTitle == '人脸采集' ? 'margin-top: 6px;' : ''">{{ item.menuTitle }}</text>
					</view>
					<view class="hcc_item1"></view>
					<view class="hcc_item1"></view>
					<view class="hcc_item1"></view>
				</view>
			</view>
			<view class="hc_item1">
				<text class="hc_txt1">餐饮服务</text>
				<view class="hc_list1">
					<view class="hcc_item1 family_bottom" v-for="(item, index) in repastList" :key="index"
						@click="jumpRepastTo(item)">
						<image class="hc_img" :src="item.icon"></image>
						<text class="hc_txt">{{ item.menuTitle }}</text>
					</view>
					<view class="hcc_item1">
					</view>
					<view class="hcc_item1">
					</view>
					<view class="hcc_item1">
					</view>
				</view>
			</view>
			<view class="hc_item1">
				<text class="hc_txt1">学生服务</text>
				<view class="hc_list1">
					<view class="hcc_item1" v-for="(item, index) in stuServiceList" :key="index"
						@click="jumpRepastTo(item)">
						<image class="hc_img" :src="item.icon"></image>
						<text class="hc_txt">{{item.menuTitle}}</text>
					</view>
					<view class="hcc_item1"> </view>
					<view class="hcc_item1"> </view>
				</view>
			</view>
			<view class="hc_item1">
				<text class="hc_txt1">家长服务</text>
				<view class="hc_list1">
					<view class="hcc_item1 family_bottom" v-for="(item, index) in famServiceList" :key="index"
						@click="jumpRepastTo(item)">
						<image class="hc_img" :src="item.icon"></image>
						<text class="hc_txt">{{ item.menuTitle }}</text>
					</view>
					<view class="hcc_item1"> </view>
					<view class="hcc_item1"> </view>
				</view>
			</view>
			<view class="hc_item1">
				<text class="hc_txt1">校园管理</text>
				<view class="hc_list1">
					<view class="hcc_item1 family_bottom" :class="{'tag': TodoLeaveNum > 0}" :data-num="TodoLeaveNum"
						v-for="(item, index) in schManageList" :key="index" @click="jumpRepastTo(item)">
						<image class="hc_img" :src="item.icon"></image>
						<text class="hc_txt">{{ item.menuTitle }}</text>
					</view>
					<view class="hcc_item1">
					</view>
					<view class="hcc_item1">
					</view>
					<view class="hcc_item1">
					</view>
				</view>
			</view>
			<!-- <mcModal :isShow="showAgreement" :content="'false'" title="服务条款和隐私协议" @cancel="notAgree" :inp="false"
				@ok="agree" cancelCor="#e4393c" okBtn="同意" cancelBtn="不同意">
				<view class="user_agreement">
					欢迎使用智初小交APP。我们非常重视您的个人信息和隐私保护，在您使用“智初小交”服务之前，请您务必仔细阅读并透彻理解<text
						@click="openUserAgreement('agreement')" class="agreement">《智初小交云平台用户服务条款》</text>和
						<text @click="openUserAgreement('policy')" class="agreement">《隐私政策》</text>。
						我们将严格按照您同意的各项条款使用您的个人信息，以便为您提供更好的服务。如果同意，请点击"同意"开始使用我们的产品和服务。
				</view>
			</mcModal> -->
			<mcModal :isShow="showMcModal" :content="content" :title="title" @cancel="bb()" :inp="false" @ok="cc()"
				:okBtn="okBtn"></mcModal>
			<tmcModal :isShow="showMcModal1" :content="content1" :title="title1" :okBtn="okBtn1" :showCancel="false"
				@ok="queren"></tmcModal>
		</view>
		<!-- #ifndef APP-PLUS -->
		<!-- <mc-tabbar :current-page="0"></mc-tabbar>  -->
		<!-- #endif -->
	</view>
</template>

<script>
	let _this;
	import {
		queryStudentCardBalance,
		selectAppInfo,
		findUserByUserId,
		getWxJsApiSignature,
		queryNewsList2,
		queryBindStudentQuantity,
		offlineQrcodeConsumeOrder,
		offlineQrcodeConsumePay,
		getTodoLeaveList,
	} from "../../common/api/index.js";
	import {
		showLoading,
		hideLoading
	} from "../../common/js/loading.js";
	import {
		_showToast,
		dateFtt,
		_showJumpModal
	} from "../../common/js/util.js";
	import mcTabbar from "../../components/mc-tarbar.vue";
	import mcModal from "../../components/custom-modal/custom-modal.vue";
	import tmcModal from "../../components/custom-modal/mc-modal.vue";
	// #ifdef H5
	import wx from "../../common/js/wx-js-sdk.js";
	// #endif
	export default {
		onLoad() {
			_this = this
			// #ifdef MP-WEIXIN
			wx.showShareMenu({
				withShareTicket: true,
				menus: ["shareAppMessage", "shareTimeline"]
			});
			// #endif
			// #ifdef APP-PLUS
			// const agreement = uni.getStorageSync("agreement")
			// if (agreement != "agree") return
			this._getAppInfo();
			// #endif

		},
		onShow: function() {
			// #ifdef APP-PLUS
			// this.showAgreement = false
			// const agreement = uni.getStorageSync("agreement")
			// if (agreement != "agree") this.showUserAgreement();
			let args = plus.runtime.arguments;
			// #endif
			setTimeout(() => {
				this.loginFlag = uni.getStorageSync("s_login");
				if (this.loginFlag) {
					this._getUserInfo();
					this._queryStudentCardBalance();
					this._queryBindStudentQuantity();
				}
			}, 800)
			// #ifdef MP-WEIXIN
			let _that = this;
			uni.getSystemInfo({
				success: function(res) {
					let info = uni.createSelectorQuery().select(".h_header");
					let info2 = uni.createSelectorQuery().select(".h_notice");
					// let info3 = uni.createSelectorQuery().select(".h_notices");
					info
						.boundingClientRect(function(data) {
							info2
								.boundingClientRect(function(datas) {
									_that.height = res.windowHeight - data.height - datas.height -
										62 + 'px';
									// info3
									//   .boundingClientRect(function(datass) {
									//     _that.height = res.windowHeight - data.height - datas.height - datass.height - 62 + 'px';
									//   })
									//   .exec();
								})
								.exec();
						})
						.exec();
				}
			});
			// #endif
		},
		components: {
			mcTabbar,
			mcModal,
			tmcModal
		},
		data() {
			return {
				// showAgreement: false,
				loginFlag: uni.getStorageSync("s_login"),
				mobileNo: "",
				sweixin: "",
				stuObj: {},
				carList: [],
				orgId: "",
				showMcModal: false,
				title: "",
				content: "",
				url: "",
				okBtn: "",
				showMcModal1: false,
				title1: "",
				content1: "",
				okBtn1: "",
				selectCard: "",
				newList: [],
				geList: [],
				height: "",
				geListStu: [],
				allQuantity: 0,
				kithQuantity: 0,
				ownQuantity: 0,
				param: "",
				orderNo: '',
				callbackObj: {},
				topSwiperIndex: 0,
				isBindMilk: false, //判断是否已经绑定奶卡
				TodoLeaveNum: 0,
				topSwiper: [{
						src: "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fres.cjyun.org%2Fa%2F10008%2F202102%2Fb8fdd78416ec9e0ee6f66c810a23f795.jpeg&refer=http%3A%2F%2Fres.cjyun.org&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1617954410&t=767fd0cce3e69e0e04028e47a69d273e"
					},
					{
						src: "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.alicdn.com%2Fimgextra%2Fi2%2F2200770744171%2FO1CN016seSBf1ggMZgAu39G_%21%212200770744171.jpg&refer=http%3A%2F%2Fimg.alicdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1617954441&t=69018de9ce197440f682afbcfffb048a"
					},
					{
						src: "/static/images/home/background.png"
					}
				],
				homeList: [{
						menuTitle: "绑卡",
						login: true,
						realName: true,
						icon: "/static/images/home/bind_card.png",
						url: '/packageCard/card/bind'
					},
					{
						menuTitle: "充值",
						icon: "/static/images/home/rechange.png",
						url: '/packageCard/card/carList'
					},
					{
						menuTitle: "缴费",
						login: true,
						bind: true,
						realName: true,
						icon: "/static/images/home/jiaofei.png",
						handle() {
							uni.navigateTo({
								url: "/pagePayment/payment/tuition?certUserInfo=" +
									JSON.stringify(_this.stuObj)
							});
						}
					},
					{
						menuTitle: "收支明细",
						login: true,
						bind: true,
						realName: true,
						icon: "/static/images/home/shou_detail.png",
						url: '/pagePayment/recode/sz_list'
					},
					{
						menuTitle: "补助查询",
						login: true,
						bind: true,
						realName: true,
						icon: "/static/images/home/bu_query.png",
						url: '/pagePayment/recode/bz_list'
					},
					{
						menuTitle: "消费记录",
						login: true,
						bind: true,
						realName: true,
						icon: "/static/images/home/xiaofeimx.png",
						url: '/pagePayment/recode/xf_list',
						handle() {
							_this._getXiaofei("消费记录")
						}
					},
					{
						menuTitle: "人脸采集",
						login: true,
						bind: true,
						realName: true,
						icon: "/static/images/home/face.png",
						url: '../me/fixPortrait',
						handle() {
							_this._toCaiji()
						}
					}
				],
				repastList: [{
						menuTitle: '预约',
						icon: '/static/images/home/booked.png',
						login: true,
						bind: true,
						realName: true,
						url: '/pages/meal/booked'
					},
					{
						menuTitle: '报餐',
						icon: '/static/images/home/meal.png',
						login: true,
						bind: true,
						realName: true,
						url: '/pages/meal/meal'
					},
				],
				stuServiceList: [{
						menuTitle: "行程申请",
						login: true,
						bind: true,
						realName: true,
						icon: "/static/images/home/stu_apply.png",
						url: "../student/qingjia"
					},
					// {
					// 	btnName: "成绩查询",
					// 	btnImg: "/static/images/home/grade_query.png"
					// },
					// {
					// 	btnName: "课程表",
					// 	btnImg: "/static/images/home/kecheng.png"
					// },
					// {
					// 	btnName: "录音",
					// 	btnImg: "/static/images/home/kecheng.png"
					// },
					// #ifdef MP-WEIXIN
					{
						menuTitle: "牛奶卡",
						login: true,
						bind: true,
						realName: true,
						icon: "/static/images/home/bind_card.png",
						handle() {
							_this._toMilk()
						}
					},
					{
						menuTitle: "宿舍",
						login: true,
						bind: true,
						realName: true,
						icon: "/static/images/home/kecheng.png",
						url: '../../hotWater/index/index'
					},
					{
						menuTitle: "云打印",
						login: true,
						bind: true,
						realName: true,
						icon: "/static/images/home/print.png",
						url: "../student/cloudprint/cloudFile"
					}
					// #endif
				],
				schManageList: [{
					menuTitle: '行程审批',
					icon: '/static/images/home/stu_apply.png',
					login: true,
					bind: true,
					realName: true,
					url: '/pageSchoolManage/approve/approveList'
				}],
				famServiceList: [{
						menuTitle: "绑定学生",
						icon: "/static/images/home/bind_stu.png",
						login: true,
						bind: true,
						realName: true,
						url: '../student/bind'
					},
					{
						menuTitle: "学生轨迹",
						icon: "/static/images/home/stu_guiji.png",
						login: true,
						bind: true,
						realName: true,
						bindKith: true,
						url: "../student/selStu?name='学生轨迹'&bindType=1",
					},
					{
						menuTitle: "学生信息",
						icon: "/static/images/home/stu_info.png",
						login: true,
						bind: true,
						realName: true,
						bindKith: true,
						url: "../student/info"
					}
				],
				QRList: [{
						menuTitle: "卡包",
						icon: "/static/images/home/cardBox.png",
						login: true,
						allBind: true,
						realName: true,
						url: '/packageCard/card/dangan'
					},
					{
						menuTitle: "二维码",
						icon: "/static/images/home/qrcodeBox.png",
						login: true,
						bind: true,
						realName: true,
						url: '/pagePayment/qrcode/qrcode'
					},
					{
						menuTitle: "扫码",
						icon: "/static/images/home/saoBox.png",
						login: true,
						bind: true,
						realName: true,
						handle() {
							// #ifdef H5
							_this._hSao();
							// #endif
							// #ifndef H5
							_this.jumpSao();
							// #endif
						}
					},
					{
						menuTitle: "卡挂失",
						icon: "/static/images/home/guaBox.png",
						login: true,
						bind: true,
						realName: true,
						url: '/packageCard/card/guashi'
					}
				],
				// #ifdef APP-PLUS
				appUrl: "",
				wgtAppUrl: ""
				// #endif
			};
		},
		methods: {
			// showUserAgreement() {
			// 	this.showAgreement = true
			// },
			// notAgree() {
			// 	plus.runtime.quit()
			// },
			// agree() {
			// 	uni.setStorageSync("agreement", "agree")
			// 	this.showAgreement = false
			// },
			openUserAgreement(name) {
				console.log(name)
				let url = '';
				if (name == 'agreement') { // 服务条款
					url = '/stu_side_h5/xj/user_agreement.html' + '&title=' + '用户服务条款'
				} else if (name == 'policy') { // 隐私协议
					url = '/stu_side_h5/xj/privacy_policy.html' + '&title=' + '隐私政策'
				}
				uni.navigateTo({
					url: '../login/userAgreement?url=' + url
				})
			},
			topSwiperTab(e) {
				this.topSwiperIndex = Number(e.target.current);
			},
			_getAppInfo() {
				selectAppInfo("xiaojiao_app_info")
					.then(res => {
						if (res.resultCode == 0) {
							let _that = this;
							plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) {
								let sysVersion = widgetInfo.version.split(".")[0];
								let selfVersion = res.versionName.split(".")[0];
								if (selfVersion > sysVersion) {
									console.log("大版本更新 ios引导去商店更新 Android直接更新包");
									_that.title1 = "更新提示";
									_that.content1 = "发现最新版本，请速速更新！";
									_that.okBtn1 = "立即更新";
									_that.showMcModal1 = true;
									// #ifdef APP-PLUS
									_that.appUrl = res.appUrl;
									_that.wgtAppUrl = res.wgtAppUrl.split("&")[0];
									// #endif
								} else if (widgetInfo.version == res.versionName) {
									console.log("已为最新版本");
									return;
								} else if (
									Number(widgetInfo.versionCode) + 1 ==
									Number(res.version)
								) {
									console.log("小版本更新");
									_that.title = "更新提示";
									_that.content = "发现最新版本，请速速更新！";
									_that.okBtn = "立即更新";
									_that.showMcModal = true;
									// #ifdef APP-PLUS
									_that.appUrl = res.appUrl;
									_that.wgtAppUrl = res.wgtAppUrl.split("&")[0];
									// #endif
								} else {}
							});
						}
					})
					.catch(err => {
						console.log(err);
					});
			},
			downWgt(wgtUrl) {
				let _tha = this;
				const APPID = "__UNI__FB2E3D4";
				plus.nativeUI.showWaiting("下载更新文件...");
				plus.downloader
					.createDownload(
						wgtUrl, {
							filename: "_doc/update/${APPID}.wgt"
						},
						function(d, status) {
							if (status == 200) {
								console.log("下载更新文件成功：" + d.filename);
								_tha.installWgt(d.filename);
							} else {
								plus.nativeUI.alert("下载更新文件失败！");
							}
							plus.nativeUI.closeWaiting();
						}
					)
					.start();
			},
			installWgt(path) {
				plus.nativeUI.showWaiting("安装更新文件...");
				plus.runtime.install(
					path, {},
					function() {
						plus.nativeUI.closeWaiting();
						console.log("安装更新文件成功！");
						// uni.showToast({
						//   title: "更新成功"
						// });
						plus.runtime.restart();
					},
					function(e) {
						plus.nativeUI.closeWaiting();
						plus.nativeUI.alert("安装更新文件失败[" + e.code + "]：" + e.message);
					}
				);
			},
			bb() {
				this.showMcModal = false;
			},
			cc() {
				this.showMcModal = false;
				if (this.okBtn == "立即更新") {
					this.downWgt(this.wgtAppUrl);
				} else if (this.okBtn == "立即下载") {
					let url = "/stu_side_h5/xj/download.html";
					uni.navigateTo({
						url: "../login/userAgreement?url=" + url
					});
					// switch (uni.getSystemInfoSync().platform) {
					//   case 'android':
					// plus.runtime.openURL(this.appUrl);
					// 	break;
					//   case 'ios':
					// plus.runtime.launchApplication({
					//   action: 'https://apps.apple.com/cn/app/%E6%99%BA%E5%88%9D%E5%B0%8F%E8%BE%BE/id1537510834'
					// }, function (e) {
					//   console.log('Open system default browser failed: ' + e.message);
					// });
					// 	break;
					//   default:
					// 	console.log('运行在开发者工具上')
					// 	break;
					// }
				} else if (this.okBtn == "确认付款") {
					showLoading('付款中...')
					offlineQrcodeConsumePay({
						orderNo: this.orderNo,
						loginOrgId: this.geListStu[0].students[0].orgId,
						empId: this.geListStu[0].students[0].empId,
						userId: uni.getStorageSync("s_userId")
					}).then(result => {
						this.showMcModal1 = false;
						if (result.resultCode == 0) {
							hideLoading()
							this.callbackObj = result;
							this.title1 = "温馨提示";
							this.content1 = '支付成功';
							this.okBtn1 = "确认";
							this.showMcModal1 = true;
						} else {
							hideLoading()
							this.title1 = "温馨提示";
							this.content1 = result.resultMsg || '支付失败';
							this.okBtn1 = "确认";
							this.showMcModal1 = true;
						}
					}).catch(err => {
						hideLoading()
						console.log(err)
					})
				} else {
					if (this.url != null) {
						uni.navigateTo({
							url: this.url
						});
					} else {
						this._QRCode();
					}
				}
			},
			queren() {
				this.showMcModal1 = false;
				if (this.okBtn1 == "立即更新") {
					if (plus.os.name == "Android") {
						plus.runtime.openURL(this.appUrl);
					} else {
						plus.runtime.launchApplication({
								action: "https://apps.apple.com/cn/app/%E6%99%BA%E5%88%9D%E5%B0%8F%E8%BE%BE/id1537510834"
							},
							function(e) {
								console.log("Open system default browser failed: " + e.message);
							}
						);
					}
				}
				if (this.content1 == "支付成功") {
					uni.navigateTo({
						url: '/pagePayment/qrcode/consumeQrcode?orderNo=' + this.callbackObj.orderNo + '&empId=' +
							this.geListStu[0].students[0].empId + '&orgId=' + this.geListStu[0].students[0].orgId
					})
				}
			},
			_queryBindStudentQuantity() {
				let s_userId = uni.getStorageSync("s_userId");
				queryBindStudentQuantity({
						userId: s_userId
					})
					.then(res => {
						if (res.code == 0) {
							this.allQuantity = res.data.allQuantity;
							this.kithQuantity = res.data.kithQuantity;
							this.ownQuantity = res.data.ownQuantity;
							this._queryAppNewsList();
						} else {
							this.allQuantity = 0;
							this.kithQuantity = 0;
							this.ownQuantity = 0;
						}
					})
					.catch(err => {
						console.log(err);
					});
			},
			_queryAppNewsList() {
				let data = [],
					stulist = [];
				this.geListStu.forEach(item => {
					stulist.push(item.students[0]);
				});
				stulist.forEach(stu => {
					data.push({
						currentPage: 1,
						pageSize: 50,
						orgId: stu.orgId,
						// empId: stu.empId,
						msgType: 0 //this.ownQuantity == 0 ? 0 : 1
					});
				});
				queryNewsList2(JSON.stringify(data))
					.then(res => {
						if (res.code == 0) {
							if (res.data != null) {
								this.newList = res.data.filter(item => {
									return item.msgRead == 0;
								});
							}
						}
					})
					.catch(err => {
						console.log(err);
					});
			},
			_toTips() {
				_showToast("敬请期待~");
			},
			jumpStuTo(name) {
				if (name == "宿舍") {
					this._toSushe();
				} else if (!this.loginFlag) {
					this.toLogin();
				} else {
					if (this.stuObj.isCert == 0) {
						switch (name) {
							case "行程申请":
								if (this.ownQuantity > 0) {
									uni.navigateTo({
										url: `../student/qingjia?orgId=${this.geListStu[0].students[0].orgId}&empId=${this.geListStu[0].students[0].empId}`
									});
								} else {
									this._toGeCard(
										"您目前还没有绑卡，请先完成绑卡！",
										"/packageCard/card/bind"
									);
								}
								break;
							case "成绩查询":
								this._toTips();
								break;
							case "云打印":
								this.jumpNavigateTo("../student/cloudprint/cloudFile");
								break;
								// case "课程表":
								// 	this._toTips();
								// 	break;
							case "宿舍":
								this._toSushe();
								break;
							case "牛奶卡":
								this._toMilk();
								break;
							case "录音":
								this._toluYin();
								break;
						}
					} else {
						this._toRenZheng();
					}
				}
			},
			_toSushe() {
				uni.navigateTo({
					url: '../../hotWater/index/index'
				})
			},
			_toMilk() {
				let path = ''
				if (this.isBindMilk) path = '../../pageMilk/index/index'
				else path = '../../pageMilk/bind/bind'
				uni.navigateTo({
					url: path
				})
			},
			_toluYin() {
				uni.navigateTo({
					url: './Test'
				})
			},
			_getXiaofei(name) {
				if (this.ownQuantity == 1) {
					this.jumpNavigateTo(
						`/pagePayment/recode/xf_list?orgId=${this.geListStu[0].students[0].orgId}&empId=${this.geListStu[0].students[0].empId}`
					)
				} else if (this.ownQuantity >= 2) {
					uni.navigateTo({
						url: `../student/selStu?name=${name}&bindType=0`
					});
				} else {
					this._toGeCard(
						"您目前还没有绑卡，请先完成绑卡！",
						"/packageCard/card/bind"
					);
				}

			},
			_toCaiji(name) {
				console.log(name)
				let phoneName = ''
				switch (uni.getSystemInfoSync().platform) {
					case 'android':
						phoneName = '应用市场'
						break;
					case 'ios':
						phoneName = 'App Store'
						break;
					default:
						phoneName = '应用市场'
						console.log('运行在开发者工具上')
						break;
				}
				// #ifndef APP-PLUS
				this.title = '温馨提示'
				this.content = `下载智初小交APP完善人脸信息，即可使用刷脸支付`
				this.okBtn = '确认'
				this.showMcModal = true
				// #endif
				// #ifdef APP-PLUS
				if (this.ownQuantity == 1) {
					uni.navigateTo({
						url: "../me/fixPortrait?orgId=" +
							this.geListStu[0].students[0].orgId +
							"&empId=" +
							this.geListStu[0].students[0].empId +
							"&empName=" +
							this.geListStu[0].students[0].empName
					});
				} else if (this.ownQuantity >= 2) {
					uni.navigateTo({
						url: `../student/selStu?name=${name}&bindType=0`
					});
				} else {
					this._toGeCard(
						"您目前还没有绑卡，请先完成绑卡！",
						"/packageCard/card/bind"
					);
				}
				// #endif
			},
			toLogin() {
				this.title = "未登录";
				this.content = "您未登录，需要登录后才能继续";
				this.url = "../login/login";
				this.okBtn = "立即登录";
				this.showMcModal = true;
			},
			jumpFamTo(name) {
				if (!this.loginFlag) {
					this.toLogin();
				} else {
					if (this.stuObj.isCert == 0) {
						switch (name) {
							case "学生信息":
								this.kithQuantity > 0 ?
									this.jumpNavigateTo("../student/info") :
									this._toGeCard(
										"您目前还没有亲友卡，请先完成绑卡！",
										"../student/bind"
									);
								break;
							case "绑定学生":
								this.jumpNavigateTo("../student/bind");
								break;
							case "云打印":
								this.jumpNavigateTo("../student/cloudprint/cloudFile");
								break;
							case "限额设置":
								this.jumpNavigateTo('../student/money-settings?arrObj=' + encodeURIComponent(JSON
									.stringify(this.geListStu[0].students)));
								break;
							case "学生轨迹":
								if (this.kithQuantity > 0) {
									uni.navigateTo({
										url: `../student/selStu?name=${name}&bindType=1`
									});
								} else {
									this._toGeCard(
										"您目前还没有亲友卡，请先完成绑卡！",
										"../student/bind"
									);
								}
								break;
						}
					} else {
						this._toRenZheng();
					}
				}
			},
			radioChange: function(e) {
				this.selectCard = e.target.value;
			},
			_toGeCard(content, url) {
				this.title = "温馨提示";
				this.content = content;
				this.url = url;
				this.okBtn = "去绑卡";
				this.showMcModal = true;
			},
			jumpQR(name) {
				if (!this.loginFlag) {
					this.toLogin();
				} else {
					if (this.stuObj.isCert == 0) {
						if (name == "卡包") {
							this.allQuantity > 0 ?
								this.jumpNavigateTo("/packageCard/card/dangan") :
								this._toGeCard(
									"您目前还没有绑卡，请先完成绑卡！",
									"/packageCard/card/bind"
								);
						}
						if (name == "二维码") {
							this.ownQuantity > 0 ?
								this.jumpNavigateTo("/pagePayment/qrcode/qrcode") :
								this._toGeCard(
									"您目前还没有个人卡，请先完成绑卡！",
									"/packageCard/card/bind"
								);
						}
						if (name == "扫码") {
							// #ifdef H5
							this._hSao();
							// #endif
							// #ifndef H5
							this.jumpSao();
							// #endif
						}
						if (name == "卡挂失") {
							this.ownQuantity > 0 ?
								this.jumpNavigateTo("/packageCard/card/guashi") :
								this._toGeCard(
									"您目前还没有个人卡，请先完成绑卡！",
									"/packageCard/card/bind"
								);
						}
					} else {
						this._toRenZheng();
					}
				}
			},
			_toRenZheng() {
				this.title = "温馨提示";
				this.content = "使用该功能前，请先完成实名认证！";
				this.url = "../me/renzheng";
				this.okBtn = "去认证";
				this.showMcModal = true;
			},
			_hSao() {
				let that = this;
				//#ifdef H5
				let url = window.location.href.split("#")[0];
				//#endif
				let appId = uni.getStorageSync("str3");
				getWxJsApiSignature({
						url: url,
						appId: appId
					}).then(res => {
						if (res.resultCode == 0) {
							wx.config({
								debug: false,
								appId: res.appId,
								timestamp: res.timeStamp,
								nonceStr: res.nonceStr,
								signature: res.signature,
								jsApiList: ["scanQRCode"]
							});
							wx.ready(function() {
								wx.checkJsApi({
									jsApiList: ["scanQRCode"],
									success: function(res) {
										if (res.checkResult.scanQRCode === true) {
											wx.scanQRCode({
												desc: "scanQRCode desc",
												needResult: 1,
												scanType: ["qrCode", "barCode"],
												success: function(res) {
													setTimeout(() => {
														const getCode = res
															.resultStr // 当needResult 为 1 时，扫码返回的结果
														if (res.resultStr
															.substr(0, 2) ==
															"98") {
															showLoading(
																'下单中...')
															offlineQrcodeConsumeOrder
																({
																	qrcode: res
																		.resultStr,
																	loginOrgId: that
																		.geListStu[
																			0
																		]
																		.students[
																			0
																		]
																		.orgId,
																	empId: that
																		.geListStu[
																			0
																		]
																		.students[
																			0
																		]
																		.empId,
																	userId: uni
																		.getStorageSync(
																			"s_userId"
																		)
																}).then(
																	result => {
																		console
																			.log(
																				result
																			)
																		that.showMcModal1 =
																			false;
																		if (result
																			.resultCode ==
																			0
																		) {
																			hideLoading
																				()
																			that.orderNo =
																				result
																				.orderNo;
																			that.title =
																				"消费提醒";
																			that.content =
																				`本次付款金额为：${result.amount}元！`;
																			that.url =
																				null;
																			that.okBtn =
																				"确认付款";
																			that.showMcModal =
																				true;
																		} else {
																			hideLoading
																				()
																			that.title1 =
																				"温馨提示";
																			that.content1 =
																				result
																				.resultMsg;
																			that.okBtn1 =
																				"确认";
																			that.showMcModal1 =
																				true;
																		}
																	}).catch(
																	err => {
																		hideLoading
																			()
																		console
																			.log(
																				err
																			)
																	})
														}
														// uni.showModal({
														// 	title: '测试',
														// 	content: `${res.resultStr}`
														// })
													})
													// if (res.confirm) {
													// 	//跳转到小程序
													// 	if (res.miniprogram) {
													// 	     wx.miniProgram.switchTab({url: '/pages/home/home'});
													// 	}
													// } else if (res.cancel) {
													//     console.log('用户点击取消');
													// }
												},
												error: function(err) {
													uni.showToast({
														title: `${JSON.stringify(res)}`
													});
												}
											});
										} else {
											uni.showToast({
												title: `${JSON.stringify(res)}`
											});
										}
									},
									fail: function(res) {
										uni.showToast({
											title: `${JSON.stringify(res)}`
										});
									}
								});
							});
							wx.error(function(res) {
								uni.showToast({
									title: `${JSON.stringify(res)}`
								});
							});
						} else {
							this.title1 = "温馨提示";
							this.content1 = res.resultMsg;
							this.showMcModal1 = true;
							this.okBtn1 = "确认";
						}
					})
					.catch(err => {
						console.log(err);
					});
			},
			jumpNavigateTo(url) {
				// console.log(url)
				uni.navigateTo({
					url: url
				});
			},
			jumpTo(name) {
				if (!this.loginFlag) {
					if (name == "充值") {
						this.jumpNavigateTo("/pagePayment/recharge/recharge");
					} else {
						this.toLogin();
					}
				} else {
					if (this.stuObj.isCert == 0) {
						switch (name) {
							case "绑卡":
								this.jumpNavigateTo("/packageCard/card/bind");
								break;
							case "充值":
								this.allQuantity > 0 ?
									this.jumpNavigateTo("/packageCard/card/carList") :
									this.jumpNavigateTo("/pagePayment/recharge/recharge");
								break;
							case "缴费":
								if (this.allQuantity > 0) {
									uni.navigateTo({
										url: "/pagePayment/payment/tuition?certUserInfo=" +
											JSON.stringify(this.stuObj)
									});
								} else {
									this._toGeCard(
										"您目前还没有卡，请先完成绑卡！",
										"/packageCard/card/bind"
									);
								}
								break;
							case "补助查询":
								this.allQuantity > 0 ?
									this.jumpNavigateTo("/pagePayment/recode/bz_list") :
									this._toGeCard(
										"您目前还没有卡，请先完成绑卡！",
										"/packageCard/card/bind"
									);
								break;
							case "收支明细":
								this.allQuantity > 0 ?
									this.jumpNavigateTo("/pagePayment/recode/sz_list") :
									this._toGeCard(
										"您目前还没有卡，请先完成绑卡！",
										"/packageCard/card/bind"
									);
								break;
							case "消费记录":
								this.allQuantity > 0 ?
									this._getXiaofei(name) :
									this._toGeCard(
										"您目前还没有卡，请先完成绑卡！",
										"/packageCard/card/bind"
									);
								break;
							case "人脸采集":
								this.allQuantity > 0 ?
									this._toCaiji(name) :
									this._toGeCard(
										"您目前还没有卡，请先完成绑卡！",
										"/packageCard/card/bind"
									);
								break;
						}
					} else {
						this._toRenZheng();
					}
				}
			},
			_queryStudentCardBalance() {
				let s_userId = uni.getStorageSync("s_userId");
				queryStudentCardBalance({
						userId: s_userId,
						queryCard: true,
						queryWallet: true,
						bindType: '0,3'
					})
					.then(res => {
						if (res.code == 0) {
							this.geListStu = res.data.students;
							this.isBindMilk = res.data.orgs.filter(item => item.bindType == 3).length > 0
							this._getTodoLeaveList()
						} else {
							this.geListStu = [];
						}
					})
					.catch(err => {
						console.log(err);
					});
			},
			_getUserInfo() {
				showLoading();
				let s_userId = uni.getStorageSync("s_userId");
				findUserByUserId({
						userId: s_userId
					})
					.then(res => {
						if (res.resultCode == 0) {
							this.mobileNo = res.obj.mobileNo;
							this.stuObj = res.obj;
							uni.setStorageSync("realname", res.obj.userName);
							uni.setStorageSync("idCard", res.obj.idCard);
							uni.setStorageSync("s_mobile", res.obj.mobileNo);
							hideLoading();
						} else {
							hideLoading();
						}
					})
					.catch(err => {
						hideLoading();
						console.log(err);
					});
			},
			jumpLogin() {
				if (this.loginFlag) {} else {
					uni.navigateTo({
						url: "../login/login"
					});
				}
			},
			jumpSao() {
				let _this = this;
				uni.scanCode({
					success: function(res) {
						console.log("条码类型：" + res.scanType);
						console.log("条码内容：" + res.result);
						if (res.result.indexOf("?") > -1) {
							_this.param = res.result.split("?")[1];
							_this.title = "温馨提示";
							_this.content = "该二维码是申能达智慧热水小程序";
							_this.url = null;
							_this.okBtn = "前往使用";
							_this.showMcModal = true;
						} else if (res.result.substr(0, 2) == "98") { // 脱机消费
							showLoading('下单中...')
							offlineQrcodeConsumeOrder({
								qrcode: res.result,
								loginOrgId: _this.geListStu[0].students[0].orgId,
								empId: _this.geListStu[0].students[0].empId,
								userId: uni.getStorageSync("s_userId")
							}).then(result => {
								_this.showMcModal1 = false;
								if (result.resultCode == 0) {
									hideLoading()
									_this.orderNo = result.orderNo;
									_this.title = "消费提醒";
									_this.content = `本次付款金额为：${result.amount}元！`;
									_this.url = null;
									_this.okBtn = "确认付款";
									_this.showMcModal = true;
								} else {
									hideLoading()
									_this.title1 = "温馨提示";
									_this.content1 = result.resultMsg;
									_this.okBtn1 = "确认";
									_this.showMcModal1 = true;
								}
							}).catch(err => {
								hideLoading()
								console.log(err)
							})
						} else {
							_this.title1 = "温馨提示";
							_this.content1 = "目前本项目只支持扫一扫跳转特定小程序";
							_this.okBtn1 = "确认";
							_this.showMcModal1 = true;
						}
					}
				});
			},
			_QRCode() {
				let _this = this;
				// #ifdef MP-WEIXIN
				uni.navigateToMiniProgram({
					appId: "wx1efb69bc00140bc7",
					path: "",
					success: function(res) {
						console.log(res);
					},
					fail: function(err) {
						console.log(err);
					},
					complete: function(e) {
						console.log(e);
					}
				});
				// #endif
				// #ifdef MP-ALIPAY
				uni.navigateToMiniProgram({
					appId: "2021001157673614",
					path: "",
					success: function(res) {
						console.log(res);
					},
					fail: function(err) {
						console.log(err);
					},
					complete: function(e) {
						console.log(e);
					}
				});
				// #endif
				// #ifdef APP-PLUS
				plus.share.getServices(
					function(res) {
						var sweixin = null;
						for (var i = 0; i < res.length; i++) {
							var t = res[i];
							if (t.id == "weixin") {
								sweixin = t;
							}
						}
						if (sweixin) {
							sweixin.launchMiniProgram({
								id: "gh_5b5232bc2726",
								type: 0, //0 正式 1 测试 2 体验  小程序的版本
								path: `pages/index/index?${_this.param}` //这里你要跳的路径，可以传值
							});
						}
					},
					function(res) {
						console.log(JSON.stringify(res));
					}
				);
				// #endif
			},
			jumpRepastTo(item) {
				if (item.login && !this.loginFlag) {
					this.toLogin()
					return
				}
				if (item.realName && this.stuObj.isCert != 0) {
					this._toRenZheng()
					return
				}
				if (item.bind && !(this.ownQuantity > 0)) {
					this._toGeCard('您目前还没有个人卡，请先完成绑卡！', '/packageCard/card/bind')
					return
				}
				if (item.bindKith && !(this.kithQuantity > 0)) {
					this._toGeCard("您目前还没有亲友卡，请先完成绑卡！", '../student/bind')
					return
				}
				if (item.allBind && !(this.allQuantity > 0)) {
					this._toGeCard("您目前还没有卡，请先完成绑卡！", '/packageCard/card/bind')
					return
				}
				if (item.handle) {
					item.handle()
					return
				}
				uni.navigateTo({
					url: item.url +
						`?orgId=${this.geListStu[0].students[0].orgId}&empId=${this.geListStu[0].students[0].empId}`
				})

			},
			_getTodoLeaveList() {
				getTodoLeaveList({
					orgId: this.geListStu[0].students[0].orgId,
					empId: this.geListStu[0].students[0].empId,
					startTime: '1990-01-01 00:00:00',
					endTime: dateFtt('yyyy-MM-dd hh:mm:ss', new Date()),
				}).then(res => {
					if (res.resultCode == 0 && res.leaveList != null) {
						this.TodoLeaveNum = res.leaveList.length
					}
				}).catch(err => {
					console.log(err)
				})
			}
		}
	};
</script>

<style lang="scss">
	page {
		background: #f6f6f6;
	}

	.home {
		background-color: #f6f6f6;
		overflow: hidden;
		height: 100vh;

		.h_header {
			width: 100vw;
			height: 390rpx;
			background-image: url("");
			background-size: 100%;
			background-repeat: no-repeat;
			position: relative;
			display: flex;
			flex-direction: row;
			align-items: center;
			padding-left: 30rpx;

			.hh_cicle {
				width: 162rpx;
				height: 192rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				margin-right: 30rpx;

				.hc_imgs {
					width: 100%;
					height: 100%;
				}
			}

			.login_box {
				display: flex;
				flex-direction: column;

				.hc_login {
					color: #ffffff;
					font-weight: 600;
					font-size: 28rpx;
				}

				.l_box_txt1 {
					color: #fff;
					font-size: 38rpx;
					margin-bottom: 20rpx;
					font-weight: 600;
				}

				.l_b_box {
					width: 500rpx;
					display: flex;
					flex: 1;
					flex-direction: row;
					justify-content: space-between;
					align-items: center;

					.l_b_login {
						height: 72rpx;
						background: linear-gradient(180deg, #ffffff 0%, #c2e1ff 100%);
						box-shadow: 0 8rpx 16rpx 0 rgba(0, 0, 0, 0.19);
						border-radius: 40rpx;
						font-size: 32rpx;
						font-family: "PingFangSC-Medium, PingFang SC";
						font-weight: 500;
						color: #002a92;
						line-height: 72rpx;
						padding: 0 38rpx;
					}
				}

				.l_login_txt {
					margin-top: 20rpx;
					font-size: 32rpx;
					color: #fff;
					font-weight: 500;
					font-family: "PingFangSC-Medium, PingFang SC";
				}
			}
		}

		.h_car {
			width: 93%;
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			align-items: center;
			position: absolute;
			top: 300rpx;
			left: 3.5%;

			.hcc_item {
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				box-shadow: 0px 8rpx 16rpx 0px rgba(7, 7, 7, 0.14);
				border-radius: 6rpx;
				overflow: hidden;

				.home_hc_img {
					width: 160rpx;
					height: 160rpx;
					position: relative;
				}

				.hc_txt {
					color: rgb(51, 51, 51);
				}

				.h_h_title {
					position: absolute;
					top: 20rpx;
					font-size: $font-size-lg;
					color: #ffffff;
				}
			}
		}

		.h_notice {
			margin-top: 100rpx;
			display: flex;
			justify-content: center;
			padding: 0 30rpx;
			margin-bottom: 20rpx;

			.h_n_box {
				width: 100%;
				display: flex;
				flex-direction: row;
				align-items: center;
				background-color: #ffffff;
				padding: 20rpx;
				border-radius: 8rpx;

				.n_img {
					width: 45rpx;
					height: 45rpx;
					margin-right: 10rpx;
				}

				.txt_box {
					flex: 1;

					.s_txt {
						font-size: $font-size-base;
						padding-left: 10rpx;
						overflow: hidden;
						white-space: nowrap;
						text-overflow: ellipsis;
					}
				}
			}
		}

		.h_content {
			display: flex;
			flex-direction: column;
			flex: 1;
			padding: 0 30rpx;
			height: calc(100vh - 295px);
			margin-bottom: 15rpx;
			overflow: scroll;

			.hc_item1 {
				width: 100%;
				background-color: #ffffff;
				padding: 32rpx;
				border-radius: 8rpx;
				margin-bottom: 20rpx;
				box-sizing: border-box;

				.hc_txt1 {
					color: rgb(51, 51, 51);
					font-weight: 800;
					font-size: 32rpx;
				}

				.hc_list1 {
					display: flex;
					flex-direction: row;
					flex-wrap: wrap;
					justify-content: space-between;
					margin-top: 48rpx;

					.hcc_item1 {
						display: flex;
						flex-direction: column;
						justify-content: center;
						align-items: center;
						width: 20%;
						margin-bottom: 20rpx;

						&.tag {
							position: relative;

							&::after {
								content: attr(data-num);
								display: block;
								position: absolute;
								right: 8rpx;
								top: 0;
								height: 32rpx;
								line-height: 32rpx;
								padding: 0 10rpx;
								border-radius: 18rpx;
								font-size: 22rpx;
								background-color: #E43D33;
								color: #FFF;
							}
						}

						.hc_img {
							width: 78rpx;
							height: 78rpx;
							margin-bottom: 8rpx;
						}

						.hc_txt {
							color: rgb(51, 51, 51);
							font-size: $font-size-base;
						}
					}
				}
			}
		}
	}

	.h_notices {
		margin-top: 20rpx;
		display: flex;
		justify-content: center;
		padding: 0 30rpx;
		margin-bottom: 20rpx;
	}

	.swiper-item {
		width: 100%;
		height: 100%;
	}

	.swiper-item image {
		width: 100%;
		height: 100%;
		display: block;
	}

	.user_agreement {
		text-align: left;
		text-indent: 60rpx;

		.agreement {
			font-family: "PingFang-SC-Medium, PingFang-SC";
			font-weight: 500;
			color: #185AFF;
			text-decoration: blink
		}
	}
</style>
